<?php

	session_start();

	require_once("appconf.php");
	require_once("lib/utility.php");
	require_once("lib/class.Template.php");

	if(!isset($_SESSION['username'])) {
		header("HTTP/1.1 401 Unauthorized");
		die();
	}


	header("Content-Type: text/xml");
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";


	$dirName = $appRoot."data/".filenameSafe($_SESSION['username'])."/templates";

	echo "<response>\n";

	//Make sure template dir exist
	if (is_dir($dirName)) {

		$handler = opendir($dirName);
		while ($file = readdir($handler)) {
			if (!is_dir($file)) {
				$templateObj = new Template($_SESSION['username'], $file);
				echo "\t<template title=\"".$templateObj->getTitle()."\" filename=\"".$file."\" changed=\"".date("Y-m-d H:i:s", filectime($dirName."\\".$file))."\">\n";
				echo "\t\t" . $templateObj->getDescription()."\n";
				echo "\t</template>\n";
			}
		}

	}

	echo "</response>\n";

?>